package com.example.demo.convert;

import com.alibaba.fastjson.serializer.ValueFilter;
import com.example.demo.annotation.CodeTableConvert;
import lombok.SneakyThrows;

import java.lang.reflect.Field;


public class SysCodeConvertHandler implements ValueFilter {
    
    @SneakyThrows
    @Override
    public Object process(Object instance, String name, Object value) {
        if (instance == null || name == null || value == null) {
            return value;
        }
        Field field =   instance.getClass().getDeclaredField(name);
        if (null != field && field.isAnnotationPresent(CodeTableConvert.class)) {
            CodeTableConvert annotation = field.getAnnotation(CodeTableConvert.class);
            String groupKey = annotation.groupKey();
            String remark = annotation.remark();
            return String.format("groupKey是:%s,属性值是:%s，备注是:%s", groupKey, value,remark);
        }
        return value;
    }
}
